import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class PageChangePanel
    
    export  class PageChangePanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public get maxPage(): int
        {
            return this._maxPage;
        }

        public set maxPage(arg1: int)
        {
            this._maxPage = arg1;
            this._curPageTxt.text = "1/" + arg1;
            return;
        }

        /* internal  */init(): void
        {
            this._nameTxt = new GTextInput();
            this._nameTxt.styleName = "GTextInput";
            this._nameTxt.maxChars = 7;
            this._nameTxt.text = "";
            this._nameTxt.move(0, 0);
            this._nameTxt.setSize(65, 20);
            addChild(this._nameTxt);
            var loc1=new GButton();
            loc1.styleName = "Button";
            loc1.label = Language.getString(32050);
            loc1.setSize(66, 22);
            loc1.move(66, -2);
            loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onQueryBtnHandler);
            addChild(loc1);
            var loc2=new GButton();
            loc2.styleName = "FirstPageButton";
            loc2.label = "";
            loc2.setSize(20, 20);
            loc2.move(132, 0);
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onFirstPangeBtnHandler);
            addChild(loc2);
            var loc3=new GButton();
            loc3.styleName = "PrevPageButton";
            loc3.label = "";
            loc3.setSize(20, 20);
            loc3.move(152, 0);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onPrevPageBtnHandler);
            addChild(loc3);
            this._curPageTxt = new GTextInput();
            this._curPageTxt.styleName = "GTextInput";
            this._curPageTxt.textField.selectable = false;
            this._curPageTxt.text = "1/20";
            this._curPageTxt.setSize(40, 20);
            this._curPageTxt.move(172, 0);
            addChild(this._curPageTxt);
            var loc4;
            (loc4 = new GButton()).styleName = "NextPageButton";
            loc4.label = "";
            loc4.setSize(20, 20);
            loc4.move(212, 0);
            loc4.addEventListener(flash.events.MouseEvent.CLICK, this.onNextPageBtnHandler);
            addChild(loc4);
            var loc5;
            (loc5 = new GButton()).styleName = "LastPageButton";
            loc5.label = "";
            loc5.setSize(20, 20);
            loc5.move(232, 0);
            loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onLastPageBtnHandler);
            addChild(loc5);
            this._skipPageTxt = new GTextInput();
            this._skipPageTxt.styleName = "GTextInput";
            this._skipPageTxt.restrict = "0-9";
            this._skipPageTxt.maxChars = 2;
            this._skipPageTxt.setSize(25, 20);
            this._skipPageTxt.move(253, 0);
            addChild(this._skipPageTxt);
            var loc6;
            (loc6 = new Object /* flash.text.TextField */()).htmlText = "<a href=\'event: 0\'><u>" + Language.getString(32051) + "</u><a>";
            loc6.x = 279;
            loc6.y = 0;
            loc6.width = 30;
            loc6.height = 20;
            loc6.textColor = 11661308;
            loc6.addEventListener(flash.events.TextEvent.LINK, this.onSkipPageLinkHandler);
            addChild(loc6);
            return;
        }

        /* internal  */onQueryBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._nameTxt.text != "") 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingQueryByName, this._nameTxt.text));
            }
            return;
        }

        /* internal  */onFirstPangeBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._curPage = 1;
            this._curPageTxt.text = "1/" + this.maxPage;
            this.sendPageChange();
            return;
        }

        /* internal  */onPrevPageBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._curPage > 1) 
            {
                var loc1;
                var loc2=((loc1 = this)._curPage - 1);
                loc1._curPage = loc2;
                this._curPageTxt.text = this._curPage + "/" + this.maxPage;
                this.sendPageChange();
            }
            return;
        }

        /* internal  */onNextPageBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._curPage < this._maxPage) 
            {
                var loc1;
                var loc2=((loc1 = this)._curPage + 1);
                loc1._curPage = loc2;
                this._curPageTxt.text = this._curPage + "/" + this.maxPage;
                this.sendPageChange();
            }
            return;
        }

        /* internal  */onLastPageBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._curPage = this._maxPage;
            this._curPageTxt.text = this._maxPage + "/" + this.maxPage;
            this.sendPageChange();
            return;
        }

        /* internal  */onSkipPageLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=parseInt(this._skipPageTxt.text);
            if (loc1 > 0 && loc1 <= this._maxPage) 
            {
                this._curPage = loc1;
                this._curPageTxt.text = loc1 + "/" + this.maxPage;
                this.sendPageChange();
            }
            return;
        }

        /* internal  */sendPageChange(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankingPageChange, this._curPage));
            return;
        }

        public setCurPage(arg1: int): void
        {
            this._curPage = arg1;
            this._curPageTxt.text = arg1 + "/" + this.maxPage;
            return;
        }

        /* internal */ /* var */_nameTxt: GTextInput;

        /* internal */ /* var */_curPageTxt: GTextInput;

        /* internal */ /* var */_skipPageTxt: GTextInput;

        /* internal */ /* var */_curPage: int=1;

        /* internal */ /* var */_maxPage: int=20;
    }
